cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA12.log", replace

clear all
set more off

mat Results = J(13, 11, -9)

use "RawData/GallupDataBJPS.dta", clear

// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Drops Obs. w/o Education
drop if education < 0
// Keeps In-Person Surveys
keep if survey == 1

// Keeps Surveys with Leaners
egen temp = max(party2), by(series)
drop if temp < -1
drop temp

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date
format middle_date %td
gen year = year(middle_date)  

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
// Partisan 1 = Leaners Ind, Partisan 2 = Leaners as Partisans
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

gen partisan2 = .5 if party == 0 & party2 == 0
replace partisan2 = 0 if party == -1 | party2 == -1
replace partisan2 = 1 if party == 1 | party2 == 1

tab partisan partisan2

gen college = (education == 5)
gen female_college = female * college

forvalues i = 1953(4)1993 {
local j = 1 + (`i' - 1953)/4
cap areg partisan female college female_college if year >= `i' & year <= `i' + 3, absorb(series)
local temp = _rc
display `i'
display `temp'
if `temp' == 0 {
mat v = e(V)
mat Results[1, `j'] = e(N)
mat Results[2, `j'] = _b[female] + _b[female_college]
mat Results[3, `j'] = -((v[1, 1] + 2*v[1, 3] + v[3, 3])^(1/2))
mat Results[4, `j'] = _b[female]
mat Results[5, `j'] = -_se[female]
mat Results[6, `j'] = _b[female_college]
mat Results[7, `j'] = -_se[female_college]
cap areg partisan2 female college female_college if year >= `i' & year <= `i' + 3, absorb(series)
mat v = e(V)
mat Results[8, `j'] = _b[female] + _b[female_college]
mat Results[9, `j'] = -((v[1, 1] + 2*v[1, 3] + v[3, 3])^(1/2))
mat Results[10, `j'] = _b[female]
mat Results[11, `j'] = -_se[female]
mat Results[12, `j'] = _b[female_college]
mat Results[13, `j'] = -_se[female_college]
}
}

matlist Results

log close
